/*=================================页面load============================================================*/

function pageLoad(){
	createLeftTopMenu();
	queryAllSettings();
	var title = getQueryString("title");
	var category = getQueryString("category");
	document.getElementById("category").innerHTML = getQueryString("category");
	document.getElementById("title").innerHTML = getQueryString("title");
	document.title = category + " - " + title;
	querySettings();
}

/*=================================信息获取============================================================*/

//获取 旅客留言的片头语
function querySettings(){
	if(bXmlHttpSupport) {
    	var sUrl = "findSettings.action";
    	var params ="item=note&setKey=note1";
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
        	if(request.readyState == 4) {
            	var oRequest = eval('(' + request.responseText + ')');
            	//alert(request.responseText);
            	var settings = oRequest.settings;
            	putSettings(settings);
			}
    	};
    	request.open('POST', sUrl);
    	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    	request.send(params);
    }
}

/*=================================信息展示============================================================*/

//行业动态页面，生成左上角的目录
function createLeftTopMenu(){
	var item = getQueryString("item");
	if(bXmlHttpSupport) {
    	var sUrl = "findSettings.action";
    	var params ="item=LeftTopMenu&setKey=" + item;
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
        	if(request.readyState == 4) {
            	var oRequest = eval('(' + request.responseText + ')');
            	//alert(request.responseText);
            	var string = oRequest.settings.setValue;
            	news.innerHTML = string;
			}
    	};
    	request.open('POST', sUrl);
    	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    	request.send(params);
    }
}

/*=================================数据处理============================================================*/
//将车站简介展示出来
function putSettings(settings){
	welcome.innerHTML = settings.setValue;
}

//保存旅客留言
function saveCustMsg(){
	//检查标题是否为空
	var msgTitle = document.getElementById("msgTitle");
	if ( msgTitle.value == ""){
		alert("主题不能为空！");
		return;
	}
	//检查新闻标题长度是否符合标准
	if (stringExceedLengthLimit(msgTitle.value, 50)){
		alert("新闻标题不能超过50个汉字！");
		return;
	}
	//检查留言内容是否为空
	var msgContent = document.getElementById("msgContent");
	if (msgContent.value == ""){
		alert("留言内容不能为空！");
		return;
	}
	//检查留言内容长度是否符合标准
	if (!stringExceedLengthLimit(msgContent.value, 10)){
		alert("留言内容最少要10个汉字！");
		return;
	}
	var msgName = document.getElementById("msgName");
	var msgMobile = document.getElementById("msgMobile");
	if(bXmlHttpSupport) {
    	var sUrl = 'saveCustMsg.action';
    	var params = 	"custMsg.title=" + msgTitle.value + "&" +
    					"custMsg.content=" + msgContent.value + "&" +
    					"custMsg.name=" + msgName.value + "&" +
    					"custMsg.mobile=" + msgMobile.value;
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
        	if(request.readyState == 4) {
        		//alert(request.responseText);
            	var oRequest = eval('(' + request.responseText + ')');
            	alert(oRequest.returnMsg);
            	resetAll();
			}
    	};
    	request.open('POST', sUrl);
    	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    	request.send(params);
    }
}

function resetAll(){
	document.getElementById("msgTitle").value = "";
	document.getElementById("msgContent").value = "";
	document.getElementById("msgName").value = "";
	document.getElementById("msgMobile").value = "";
}
